import 'package:flutter/material.dart';
import 'package:ribo_base_core/base_models/base_chart_model.dart';
import 'package:ribo_base_core/base_models/base_chart_nested_pies_model.dart';
import 'base_chart.dart';

class BaseChartNestedPies extends StatefulWidget {
  BaseChartNestedPies({Key key, @required this.model}) : super(key: key);
  final BaseChartNestedPiesModel model;

  @override
  _BaseChartPieState createState() => _BaseChartPieState();
}

class _BaseChartPieState extends State<BaseChartNestedPies> {
  Map<String, dynamic> _option;

  @override
  Widget build(BuildContext context) {
    _handleModel();
    return BaseChart(
      model: BaseChartModel(
          style: widget.model?.style,
          option: this._option),
    );
  }

  void _handleModel(){
    this._option = {
      "tooltip": {
        "trigger": 'item',
        "formatter": widget.model?.tooltipFormatter?.toJson(),
      },
      "avoidLabelOverlap": true,
      "labelLayout":{
        "hideOverlap": true,
        "moveOverlap": "shiftY"
      },
      "series": [
        {
          'type': 'pie',
          'selectedMode': 'single',
          'radius': [0, '30%'],
          'label': {
            'position': 'inner',
            'fontSize': 10,
            'overflow': 'break'
          },
          'labelLine': {
            'show': false
          },
          'data': widget.model?.innerData
        },
        {
          'type': 'pie',
          'selectedMode': 'single',
          'radius': ['35%', '55%'],
          'label': {
            'formatter': widget.model?.labelFormatter?.toJson(),
            'fontSize': 10,
            'overflow': 'break'
          },
          'data': widget.model?.data,
          'labelLine': {
            'show': true, 'length': 12, 'length2': 5
          }
        },
      ]
    };
  }
}
